class SegTree:
    def __init__(self, data):
        self.data = data
        self.n = len(data)
        self.nodes = [0] * (4 * self.n)
        self._build(1, 0, self.n - 1)

    def _build(self, o, l, r):
        data = self.data
        if l == r:
            self.nodes[o] = data[l]
            return
        mid = (r + l) // 2
        self._build(o * 2, l, mid)
        self._build(o * 2 + 1, mid + 1, r)
        self._merge(o)

    def _merge(self, o):
        ln, rn = o * 2, o * 2 + 1
        self.nodes[o] = max(self.nodes[ln], self.nodes[rn])

    def _mergeinfo(self, v1, v2):
        return max(v1,v2)

    def _query(self, A, B, l, r, o):
        nodes = self.nodes
        if A <= l and r <= B:
            return nodes[o]
        mid = (l + r) >> 1
        if B <= mid:
            return self._query(A,B,l,mid,o << 1)
        if mid < A:
            return self._query(A,B,mid + 1,r,o << 1 | 1)
        vl = self._query(A,B,l,mid,o << 1)
        vr = self._query(A,B,mid + 1,r,o << 1 | 1)
        return self._mergeinfo(vl,vr)
    def update(self,A,B,v):
        return self._update(A,B,0,self.n - 1,v,1)

    def _update(self,A,B,l,r,v,o):
        if l == r:
            self.data[l] = v
            self.nodes[o] = v
            return
        mid = (l + r) // 2
        if B <= mid:
            self._update(A,B,l,mid,v,o << 1)
        else:
            self._update(A,B,mid + 1,r,v,o << 1 | 1)
        self._merge(o)

    def query(self, a, b):
        return self._query(a, b, 0, self.n - 1, 1)